package com.atguigui.leetcode;

import java.util.Arrays;

/**
 * 467.环绕字符串中唯一的子字符串
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/5/25 22:49
 */
public class P467UniqueSubstringsInWraparoundString {
    public static void main(String[] args) {
        Solution solution = new P467UniqueSubstringsInWraparoundString().new Solution();
        solution.findSubstringInWraproundString("zaba");
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findSubstringInWraproundString(String p) {
            int[] dp = new int[26];
            int k = 0;
            for (int i = 0; i < p.length(); ++i) {
                if (i > 0 && (p.charAt(i) - p.charAt(i - 1) + 26) % 26 == 1) { // 字符之差为 1 或 -25
                    ++k;
                } else {
                    k = 1;
                }
                //
                dp[p.charAt(i) - 'a'] = Math.max(dp[p.charAt(i) - 'a'], k);
            }
            return Arrays.stream(dp).sum();
        }
    }
}
